<?php
$usrname= $_POST['usrname'];
$password= $_POST['password'];
$mailbox= $_POST['email'];
$sex=$_POST['sex'];
$conn=mysql_connect("localhost:3306", "root", "root") or die("ERROR: Cannot open database");
$db = "footprintdb";
mysql_select_db($db) or die("ERROR: Cannot open database");
$table = "usrtable";
$sql = "SELECT * FROM usrtable";
$result = mysql_query ( $sql ) or die (  "Error in query execution. ");
$hasname = false;
$uid=-1;
if (mysql_num_rows ( $result ) > 0) 
{
	while ( $row = mysql_fetch_array ( $result ) ) 
	{
		if ($row ['UsrName'] == $usrname) 
		{
			$hasname = true;
		}
	}
}
if( $hasname == true)
	die ( "Already has registered ");
else
{
	$sql="INSERT INTO usrtable (UsrName, Password, Mailbox, Sex) 
	VALUES 
	('$usrname', '$password','$mailbox','$sex' )";
	mysql_query ( $sql ) or die ( "Error in query execution. ");
	$sql = "SELECT * FROM usrtable WHERE UsrName = '".$usrname."'";
	$result = mysql_query ( $sql ) or die ( "Error in query execution. ");
	$row = mysql_fetch_array ( $result );
	$uid=$row['UsrID'];
	mkdir("./".$uid,0777);
	chmod("./".$uid, 0777) ; 
	echo $uid;
}
mysql_close($conn);
?>